package cn.ffcs.util.context;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

import cn.ffcs.security.model.User;
import cn.ffcs.security.web.UserContext;

/**
 * 
 * 应用上下文处理工具<br/> <table>
 * <tr>
 * <td>负责人/principal: </td>
 * <td colspan="2">liuzhh</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:</td>
 * <td>修改人:</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author liuzhh
 * @version $Id$
 */
public class ApplicationContextUtil
{
    
    private UserContext userContext;
    
    /**
     * 
     * 获取HttpServletRequest
     * @return
     */
    public static HttpServletRequest getHttpServletRequest(){
        ActionContext ctx = ActionContext.getContext();
        HttpServletRequest request = (HttpServletRequest) ctx
                .get(ServletActionContext.HTTP_REQUEST);
        
        return request;
    }
    
    /**
     * 
     * 获取HttpServletResponse
     * @return
     */
    public static HttpServletResponse getHttpServletResponse(){
        ActionContext ctx = ActionContext.getContext();
        HttpServletResponse response = (HttpServletResponse) ctx
                .get(ServletActionContext.HTTP_RESPONSE);
        return response;
    }
    
    /**
     * 
     * 获取HttpServletResponse
     * @return
     */
    public static String getContextObject(String param){
        
        String result=getHttpServletRequest().getParameter(param);
        
        return result;
    } 
    
    /**
     * 
     * 获取上下文信息
     * @return
     */
    public static UserContext getUserContext(HttpServletRequest request){
        /** 用户标识**/
        String LOGIN_USER_CONTEXT_=Constant.LOGIN_USER_CONTEXT_;
        UserContext userContext=(UserContext)request.getSession().getAttribute(LOGIN_USER_CONTEXT_);
        return userContext;
    }
    /**
     * 
     * 获取上下文信息
     * @return
     */
    public static UserContext getUserContextObject(){
        /** 用户标识**/
        String LOGIN_USER_CONTEXT_=Constant.LOGIN_USER_CONTEXT_;
        UserContext userContext=(UserContext)getHttpServletRequest().getSession().getAttribute(LOGIN_USER_CONTEXT_);
        return userContext;
    } 
    /**
     * 
     * 获取上下文信息
     * @return
     */
    public static void setUserContext(HttpServletRequest request,UserContext userContext){
        /** 用户标识**/
        String LOGIN_USER_CONTEXT_=Constant.LOGIN_USER_CONTEXT_;
        request.getSession().setAttribute(LOGIN_USER_CONTEXT_,userContext);
    }   
}
